/**
*****************************************************************************
 * DESC ：. 
 * Author : Junwei Zhang 
 * CREATEDATE ：2012-7-4 
 * MODIFYLIST ：       	Name 			 Date 			Reason/Contents
 * 				------------------------------------------------------ 
 * 				 	Junwei Zhang     2012-7-4		Created.
 ****************************************************************************
**/
package com.me.client;

import java.io.BufferedReader;
import java.io.IOException;

/**
 * 
 * <br/> 上午8:50:04 2012-7-4
 * @Author <a href="mailto:mestudying@sina.com">Junwei Zhang</a><br/>
 **/
public class JTalkClientThread extends Thread {
	
	private JTalkClient parent = null;
	private BufferedReader in = null;
	private String lastPackage = null;
	/** Stop the loop. */
	private boolean stopNow = false;

	public JTalkClientThread(JTalkClient jTalkClient, BufferedReader in) {
		this.parent = jTalkClient;
		this.in = in;
		this.setName("JTalkClientThread-" + this.toString());
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		try {
			while((this.lastPackage = in.readLine()) != null && !"null".equals(this.lastPackage)){
				System.out.println("[recv]: " + this.lastPackage);
				if(this.stopNow){
					return;
				}
				if(!this.parent.myProtocal.processServerPackage(this.lastPackage)){
					System.err.println("*** Thread: Faulty package recieved: "
							+ this.lastPackage);
				}
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			System.err.println("*** Thread: Main-loop-error: " + e.getMessage());
		}
	}

	public void terminate() {
		this.stopNow = true;
	}
	
	
}
